package com.citybox.web.controller.wx;

import com.citybox.domain.wx.LoginRequestDo;
import com.citybox.domain.wx.LoginResultDo;
import com.citybox.domain.wx.TokenRefreshRequestDo;
import com.citybox.domain.wx.TokenRefreshResultDo;
import com.citybox.infrastructure.wx.persistence.service.WxService;
import com.citybox.shared.web.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhao.x
 */
@Tag(name = "微信api(这个里面不拦截Token)")
@RestController
@RequestMapping(value = "/auth")
@Slf4j
public class WxController {

    @Resource
    private WxService wxService;

    @Operation(summary = "登陆")
    @PostMapping("/login")
    public R<LoginResultDo> login(@Valid @RequestBody LoginRequestDo request) {
        return wxService.wechatLogin(request);
    }

    @Operation(summary = "刷新Token")
    @PostMapping("/refresh")
    public R<TokenRefreshResultDo> refreshToken(@Valid @RequestBody TokenRefreshRequestDo request) {
        return wxService.refreshToken(request);
    }

    @Operation(summary = "获取用户手机号")
    @GetMapping("/getUserPhoneNumber")
    public R<String> getUserPhoneNumber(@RequestParam("code") String code) {
        return wxService.getUserPhoneNumber(code);
    }
}
